home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / des3.zip / WINVALID.C < prev   
C/C++ Source or Header  |  1995-04-01  |  4KB  |  133 lines

  1. #include <windows.h>
  2. #if !defined(_WIN32) && !defined(WIN32)
  3. #include <ver.h>
  4. #endif
  5. #include "des3.h"
  6.  
  7. #if !defined (APIENTRY)
  8. #define APIENTRY PASCAL
  9. #endif
  10.  
  11. BOOL InitApplication(HANDLE);
  12. BOOL InitInstance(HANDLE, int);
  13. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  14.  
  15. HINSTANCE hInst;
  16.  
  17. #ifdef WIN16
  18. char szAppName[] = "W16VALID";  
  19. char szTitle[]   = "ECB Certification of the DES Algorithm in WIN16"; 
  20. #endif
  21. #ifdef WIN32
  22. char szAppName[] = "W32VALID";
  23. char szTitle[]   = "ECB Certification of the DES Algorithm in WIN32";
  24. #endif
  25.  
  26. #define IDM_RUN 100
  27. /* size of standard DES block, in bits */
  28. #define    BITSZ    (64)
  29. /* size of standard DES block, in bytes */
  30. #define    BLKSZ    (8)
  31. /* how many standard DES blocks defined in ANSI X9.9 Appendix B */
  32. #define    X99MX    (4)
  33.  
  34. #pragma argsused
  35. int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
  36. {
  37.   MSG msg;
  38.   if (!hPrevInstance) {
  39.     if (!InitApplication(hInstance)) {
  40.       return (FALSE);
  41.     }
  42.   }
  43.   if (!InitInstance(hInstance, nCmdShow)) {
  44.     return (FALSE);
  45.   }
  46.   while (GetMessage(&msg,NULL,0,0)) {
  47.     TranslateMessage(&msg);
  48.     DispatchMessage(&msg);
  49.   }
  50.   return (msg.wParam);
  51. }
  52.  
  53. BOOL InitApplication(HINSTANCE hInstance)
  54. {
  55.   WNDCLASS  wc;
  56.  
  57.   wc.style         = CS_HREDRAW | CS_VREDRAW;
  58.   wc.lpfnWndProc   = (WNDPROC)WndProc;
  59.   wc.cbClsExtra    = 0;
  60.   wc.cbWndExtra    = 0;
  61.   wc.hInstance     = hInstance;
  62.   wc.hIcon         = LoadIcon (hInstance, szAppName);
  63.   wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  64.   wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  65.   wc.lpszMenuName  = NULL;
  66.   wc.lpszClassName = szAppName;
  67.   return (RegisterClass(&wc));
  68. }
  69.  
  70. #pragma argsused
  71. BOOL InitInstance(HINSTANCE hInstance,int nCmdShow)
  72. {
  73.   HWND hWnd;
  74.   hInst = hInstance;
  75.   hWnd = CreateWindow(szAppName,szTitle, WS_OVERLAPPEDWINDOW,
  76.                      0, 0, 0, 0, NULL, NULL, hInstance, NULL);
  77.   if (!hWnd) return (FALSE);
  78.   PostMessage(hWnd, WM_COMMAND, IDM_RUN, 0L);
  79.   return (TRUE);
  80. }
  81.  
  82. LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM uParam,LPARAM lParam)
  83. {
  84.   int wmId,i;
  85.   /* for validation, keybits and patterns taken from ANSI X9.9 Appendix B */
  86.   static uchar keybits[BLKSZ] = { 0xe6,0xa1,0x2f,0x07,0x9d,0x15,0xc4,0x37 };
  87.   static uchar pattern[X99MX][BLKSZ] = {
  88.        { 0x0a,0x20,0x20,0x20,0x54,0x4f,0x20,0x59 },
  89.        { 0x51,0x44,0x2d,0x38,0x30,0x20,0x30,0x37 },
  90.        { 0x54,0x4f,0x20,0x59,0x4f,0x55,0x52,0x20 },
  91.        { 0x51,0x44,0x2d,0x38,0x30,0x20,0x30,0x37 }
  92.   };
  93.   static uchar results[X99MX][BLKSZ], clrtext[X99MX][BLKSZ], round[BITSZ], buf[X99MX*BITSZ];
  94.   switch (message) {
  95.      case WM_COMMAND:
  96. #if defined (_WIN32) || defined(WIN32)
  97.        wmId    = LOWORD(uParam);
  98. #else
  99.        wmId    = uParam;
  100. #endif
  101.        switch (wmId) {
  102.          case IDM_RUN:
  103.            desinit(keybits);
  104.            for (i = 0; i < X99MX; i++) {
  105.              ecbencode(pattern[i],results[i]);
  106.              ecbdecode(results[i],clrtext[i]);
  107.            }
  108.            for (i = 0; i < X99MX; i++) {
  109.              wsprintf(round,"ECB %02x%02x%02x%02x%02x%02x%02x%02x -> %02x%02x%02x%02x%02x%02x%02x%02x -> %02x%02x%02x%02x%02x%02x%02x%02x\n",
  110.              pattern[i][0], pattern[i][1], pattern[i][2], pattern[i][3],
  111.              pattern[i][4], pattern[i][5], pattern[i][6], pattern[i][7],
  112.              results[i][0], results[i][1], results[i][2], results[i][3],
  113.              results[i][4], results[i][5], results[i][6], results[i][7],
  114.              clrtext[i][0], clrtext[i][1], clrtext[i][2], clrtext[i][3],
  115.              clrtext[i][4], clrtext[i][5], clrtext[i][6], clrtext[i][7]);
  116.              lstrcat(buf,round);
  117.            }
  118.            MessageBox(hWnd,buf,szTitle,MB_OK);
  119.            SendMessage(hWnd, WM_DESTROY, 0, 0L);
  120.            break;
  121.          default:
  122.            return (DefWindowProc(hWnd, message, uParam, lParam));
  123.        }
  124.        break;
  125.      case WM_DESTROY:
  126.        PostQuitMessage(0);
  127.        break;
  128.     default:
  129.       return (DefWindowProc(hWnd, message, uParam, lParam));
  130.    }
  131.    return (0);
  132. }
  133.